package com.gitee.wsl.ext.list

fun <T> ArrayDeque<T>.push(item: T) = this.addFirst(item)

fun <T> ArrayDeque<T>.popOrNull(): T? =this.removeFirstOrNull()

fun <T> ArrayDeque<T>.pop(): T = popOrNull()?: throw IndexOutOfBoundsException()

fun <T> ArrayDeque<T>.pollOrNull() = popOrNull()

fun <T> ArrayDeque<T>.poll():T = pollOrNull()?:throw IndexOutOfBoundsException()


inline fun <T> ArrayDeque<T>.usePop(block: (T) -> Unit) = popOrNull()?.let(block)

fun <T> ArrayDeque<T>.peekFirst(): T? = this.firstOrNull()

fun <T> ArrayDeque<T>.peekOrNull(): T? = this.peekFirst()

fun <T> ArrayDeque<T>.peek(): T = peekOrNull()?: throw IndexOutOfBoundsException()

inline fun <T> ArrayDeque<T>.usePeek(block: (T) -> Unit) = peekOrNull()?.let(block)        